/**
 * @author 陈泰来
 * @version V1.0
 * @Project echo-java-base
 * @Title 鸭子模拟器
 * @Description 复合模式：用到了组合、 适配器模式、迭代器模式、工厂模式、观察者模式
 * @Package designmodel.composite.simulator
 * @date 2021/3/2 4:21 下午
 * @Copyright:学如逆水行舟，不进则退 .
 */
package designmodel.composite.simulator;

import designmodel.composite.Flock;
import designmodel.composite.Quackable;
import designmodel.composite.factory.AbstractDuckFactory;
import designmodel.composite.factory.WrapperDuckFactory;
import designmodel.composite.observer.Quacklogist;
import designmodel.composite.wrapper.QuackWrapper;

public class DuckSimulator3 {

    public static void main(String[] args) throws InterruptedException {

        AbstractDuckFactory duckFactory = new WrapperDuckFactory();
        DuckSimulator3 duckSimulator = new DuckSimulator3();
        duckSimulator.simulate(duckFactory);
    }

    void simulate(AbstractDuckFactory duckFactory) throws InterruptedException {

        //所有鸭群
        Flock flockOfDucks = new Flock();
        //绿头鸭群
        Flock flockOfMallards = new Flock();


        Quackable redheadDuck = duckFactory.createRedheadDuck();
        Quackable duckCall = duckFactory.createDuckdCall();
        Quackable rubberDuck = duckFactory.createRubberDuck();

        Quackable mallard1 = duckFactory.createMallardDuck();
        Quackable mallard2 = duckFactory.createMallardDuck();
        Quackable mallard3 = duckFactory.createMallardDuck();
        Quackable mallard4 = duckFactory.createMallardDuck();
        Quackable mallard5 = duckFactory.createMallardDuck();

        flockOfDucks.add(redheadDuck);
        flockOfDucks.add(duckCall);
        flockOfDucks.add(rubberDuck);

        flockOfMallards.add(mallard1);
        flockOfMallards.add(mallard2);
        flockOfMallards.add(mallard3);
        flockOfMallards.add(mallard4);
        flockOfMallards.add(mallard5);

        flockOfDucks.add(flockOfMallards);


        System.out.println(">>>>>>鸭子模拟器启动");

        simulate(flockOfDucks);

        System.out.println(">>>>>>鸭子总共叫了:" + QuackWrapper.getQuacks() + "次!");

    }

    void simulate(Quackable duck) {
        duck.quack();
    }
}
